package com.marvels.financial.consum.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.marvels.approve.loan.dto.CascadeChannelDto;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.umservice.service.RealNameAuthentyService;
import com.marvels.dubbo.umservice.service.UserInfoService;
import com.marvels.financial.consum.FinancialConsumerUmApi;
import com.marvels.financial.funds.dto.CmsEmployeeInfoDTO;
import com.marvels.financial.loan.dto.RealNameAuthentication;
import com.marvels.financial.loan.dto.User;

@Component
public class FinancialConsumerUmImpl implements FinancialConsumerUmApi{

	@Autowired
	private UserInfoService userInfoService;
	
	@Autowired
	private RealNameAuthentyService realNameAuthenticationService;
	
	@Override
	public RealNameAuthentication querByIdentiyCardNo(String custIdCard) {
		com.fintech.user.entity.RealNameAuthentication apiResult = realNameAuthenticationService.querByIdentiyCardNo(custIdCard);
		RealNameAuthentication result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), RealNameAuthentication.class);
		MarvelsLogUtil.getInstance().info("ApproveConsumerProductApi.mcptChannelInfo direct call success!");
		return result;
	}

	@Override
	public User queryUserByMobileNo(String mobile, String type) {
		try {
			com.fintech.user.entity.User apiResult = userInfoService.queryUserByMobileNo(mobile, type);
			User result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), User.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerUmApi.queryUserByMobileNo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerUmApi.queryUserByMobileNo error", e);
			return null;
		}
	}

	@Override
	public RealNameAuthentication queryByUserId(Integer userId) {
		com.fintech.user.entity.RealNameAuthentication apiResult = realNameAuthenticationService.queryByUserId(userId);
		RealNameAuthentication result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), RealNameAuthentication.class);
		MarvelsLogUtil.getInstance().info("ApproveConsumerProductApi.mcptChannelInfo direct call success!");
		return result;
	}

	@Override
	public String insertShortUrl(String param, String loanId) {
		String result = userInfoService.insertShortUrl(param, loanId);
		return result;
	}

	@Override
	public User queryUserById(Integer userId) {
		try {
			com.fintech.user.entity.User apiResult = userInfoService.queryUserById(userId);
			User result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), User.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerUmApi.queryUserById direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerUmApi.queryUserById error", e);
			return null;
		}
	}

	@Override
	public List<CmsEmployeeInfoDTO> findUserIdByEmp(Integer userId, Integer userType) {
		MarvelsLogUtil.getInstance().info("FinancialConsumerUmApi.findUserIdByEmp direct call success, but unrealized!");
		return null;
	}

}
